package com.rainbow.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rainbow.modules.sys.entity.Permission;
import com.rainbow.modules.sys.mapper.PermissionMapper;
import com.rainbow.modules.sys.service.PermissionService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Auth rainbow
 */
@Service
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permission> implements PermissionService {

    @Override
    public List<Permission> findByUserId(String userId) {
        return baseMapper.findByUserId(userId);
    }

    @Override
    public List<Permission> findByLevelOrderBySortOrder(Integer level) {
        return list(new QueryWrapper<Permission>().eq("level", level));
    }

    @Override
    public List<Permission> findByParentIdOrderBySortOrder(String parentId) {

        return list(new QueryWrapper<Permission>().eq("parent_id", parentId));
    }

    @Override
    public List<Permission> findByTypeAndStatusOrderBySortOrder(Integer type, Integer status) {

        return list(new QueryWrapper<Permission>().eq("type", type).eq("status", status));
    }

    @Override
    public List<Permission> findByTitle(String title) {

        return list(new QueryWrapper<Permission>().eq("title", title));
    }

    @Override
    public List<Permission> findByTitleLikeOrderBySortOrder(String title) {

        return list(new QueryWrapper<Permission>().like("title", title));
    }
}
